﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Configuration;

namespace WF.ViewModels
{
    public abstract class BoFactoryBase
    {
        //protected IDataLayer _DataLayer;
        protected virtual void CreateDataLayer()
        {
            //_DataLayer = new WF.DataLayer.LINQDataLayer();
        }

        /*
        public virtual BusinessObject.Department CreateDepartmentBO()
        {
            //if (_DataLayer == null)
            //    CreateDataLayer();
            return new BusinessObject.Department();
        }

        public virtual BusinessObject.Employee CreateEmployeeBO()
        {
            //if (_DataLayer == null)
            //    CreateDataLayer();
            return new BusinessObject.Employee();
        }

        public virtual BusinessObject.Job CreateJobBO()
        {
            //if (_DataLayer == null)
            //    CreateDataLayer();
            return new BusinessObject.Job();
        }

        public virtual BusinessObject.JobLevelRelation CreateJobLevelRelationBO()
        {
            //if (_DataLayer == null)
            //    CreateDataLayer();
            return new BusinessObject.JobLevelRelation();
        }

        public virtual BusinessObject.JobLevel CreateJobLevelBO()
        {
            //if (_DataLayer == null)
            //    CreateDataLayer();
            return new BusinessObject.JobLevel();
        }

        public virtual BusinessObject.Position CreatePositionBO()
        {
            //if (_DataLayer == null)
            //    CreateDataLayer();
            return new BusinessObject.Position();
        }
        
         //add 2010.08.23
        public virtual BusinessObject.DepartmentAdjustApply CreateDepartmentAdjustApplyBO()
        {
            //if (_DataLayer == null)
            //    CreateDataLayer();
            return new BusinessObject.DepartmentAdjustApply();
        }

        public virtual BusinessObject.DepartmentAdjustHistory CreateDepartmentAdjustHistoryBO()
        {
            //if (_DataLayer == null)
            //    CreateDataLayer();
            return new BusinessObject.DepartmentAdjustHistory();
        }
        public virtual BusinessObject.EmployeeAdjustApply CreateEmployeeAdjustApplyBO()
        {
            //if (_DataLayer == null)
            //    CreateDataLayer();
            return new BusinessObject.EmployeeAdjustApply();
        }

        public virtual BusinessObject.EmployeeAdjustHistory CreateEmployeeAdjustHistoryBO()
        {
            //if (_DataLayer == null)
            //    CreateDataLayer();
            return new BusinessObject.EmployeeAdjustHistory();
        }

        internal BusinessObject.WF_TopPosition CreateTopPositionBO()
        {
            return new BusinessObject.WF_TopPosition();
        }

        internal BusinessObject.DeptKindSetting CreateDeptKindSetting()
        {
            return new BusinessObject.DeptKindSetting();
        }

        internal BusinessObject.EmployeeDimissionInfo CreateEmployeeDimissionInfo()
        {
            return new BusinessObject.EmployeeDimissionInfo();
        }
        */

        public virtual BusinessObject.SystemSetting CreateSystemSettingBO()
        {
            //if (_DataLayer == null)
            //    CreateDataLayer();
            return new BusinessObject.SystemSetting();
        }

        public virtual BusinessObject.NameValuePair CreateNameValuePairBO()
        {
            //if (_DataLayer == null)
            //    CreateDataLayer();
            return new BusinessObject.NameValuePair();
        }

        public virtual BusinessObject.WF_ApplyInstance CreateWF_ApplyInstanceBO()
        {
            //if (_DataLayer == null)
            //    CreateDataLayer();
            return new BusinessObject.WF_ApplyInstance();
        }

        public virtual BusinessObject.WF_ApplyInstanceDetail CreateWF_ApplyInstanceDetailBO()
        {
            //if (_DataLayer == null)
            //    CreateDataLayer();
            return new BusinessObject.WF_ApplyInstanceDetail();
        }

        public virtual BusinessObject.WF_ApplyInstanceStateDetail CreateWF_ApplyInstanceStateDetailBO()
        {
            //if (_DataLayer == null)
            //    CreateDataLayer();
            return new BusinessObject.WF_ApplyInstanceStateDetail();
        }

        public virtual BusinessObject.WF_AuditHistory CreateWF_AuditHistoryBO()
        {
            //if (_DataLayer == null)
            //    CreateDataLayer();
            return new BusinessObject.WF_AuditHistory();
        }

        internal BusinessObject.WF_ApplyType CreateWF_ApplyType()
        {
            return new BusinessObject.WF_ApplyType();
        }

        internal BusinessObject.KQApply CreateKQApply()
        {
            return new BusinessObject.KQApply();
        }
    }


    //public class TestBoFactory : BoFactoryBase
    //{
    //    public TestBoFactory(IDataLayer Datalayer)
    //    {
    //        _DataLayer = Datalayer;
    //    }
    //}

    public class WebTestBoFactory : BoFactoryBase
    {

        protected override void CreateDataLayer()
        {
            //HttpContext ctx = HttpContext.Current;

            //try
            //{
            //    string DatabaseMode = ConfigurationManager.AppSettings["DatabaseMode"].ToLower();
            //    if (DatabaseMode == "debug")
            //    {
            //        string memDbString = ConfigurationManager.AppSettings["DataLayerConnectionString"];
            //        _DataLayer = ctx.Application[memDbString] as IDataLayer;
            //    }
            //    else
            //    {
            //        _DataLayer = new WF.DataLayer.LINQDataLayer();
            //    }
            //}
            //catch
            //{
            //    _DataLayer = new WF.DataLayer.LINQDataLayer();
            //}
        }
    }
}
